package com.artron.mediaartron.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.v4.app.Fragment;

import com.artron.baselib.base.BaseFragment;
import com.artron.baselib.utils.ToastUtil;
import com.artron.mediaartron.R;
import com.artron.mediaartron.data.production.SuitableSizeHelper;
import com.artron.mediaartron.ui.fragment.detail.ArtDeskCalendarDetailFragment;
import com.artron.mediaartron.ui.fragment.detail.CalendarDetailFragment;
import com.artron.mediaartron.ui.fragment.detail.CustomMadeDetailFragment;
import com.artron.mediaartron.ui.fragment.detail.PosterDetailFragment;
import com.artron.mediaartron.ui.fragment.detail.VoyageDetailFragment;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;


/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-09-21.
 */

public class HomeDetailActivity extends AppBaseActivity {


    public static final String TYPE = "Type";

    @IntDef({CUSTOM_MADE, POSTER, VOYAGE, ART_DESK_CALENDAR, CALENDAR})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type{}

    public static final int CUSTOM_MADE = 1000;
    public static final int CALENDAR = 1001;
    public static final int POSTER = 1002;
    public static final int VOYAGE = 1003;
    public static final int ART_DESK_CALENDAR = 1004;

    public static void start(Context context, @Type int type) {
        Intent starter = new Intent(context, HomeDetailActivity.class);
        starter.putExtra(TYPE, type);
        context.startActivity(starter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_general;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        BaseFragment fragment = null;
        switch (getType()) {
            case CUSTOM_MADE:
                mTvTitle.setText("框画定制");
                fragment = CustomMadeDetailFragment.newInstance();
                break;
            case POSTER:
                mTvTitle.setText("海报");
                fragment = PosterDetailFragment.newInstance();
                break;
            case CALENDAR:
                mTvTitle.setText("挂历");
                fragment = CalendarDetailFragment.newInstance();
                break;
            case VOYAGE:
                mTvTitle.setText("旅行记");
                fragment = VoyageDetailFragment.newInstance();
                break;
            case ART_DESK_CALENDAR:
                mTvTitle.setText("台历");
                fragment = ArtDeskCalendarDetailFragment.newInstance();
                break;
        }


        List<Fragment> fragments = getSupportFragmentManager().getFragments();
        if (fragments == null || fragments.size() == 0) {
            addFragment(R.id.General_content,fragment, false);
        } else {
            replaceFragment(R.id.General_content, fragment, false);
        }
    }

    @Override
    protected void initActionBar() {
        super.initActionBar();
        getWindow().setBackgroundDrawableResource(android.R.color.white);

        mToolbar.setNavigationIcon(R.drawable.ic_back);
    }

    private int getType() {
        Intent intent = getIntent();
        return intent.getIntExtra(TYPE, CUSTOM_MADE);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        SuitableSizeHelper.getHelper().release();
    }

    @Override
    protected void onResume() {
        super.onResume();
        SuitableSizeHelper.getHelper().release();
    }
}
